package com.example.guardian.anticheatguard;

import androidx.lifecycle.ViewModelProvider;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
import android.widget.Toast;

import com.example.guardian.R;
import com.example.guardian.home.ChatActivity;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;
import com.youth.banner.loader.ImageLoaderInterface;

import java.util.ArrayList;
import java.util.List;

public class AntiCheatGuardFragment extends Fragment {

    private Banner banner;
    private AntiCheatGuardViewModel mViewModel;
    public static AntiCheatGuardFragment newInstance() {
        return new AntiCheatGuardFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                            @Nullable Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.anti_cheat_guard_fragment, container, false);

        ImageButton neo_button = view.findViewById(R.id.neo4j);

        neo_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(),neofj.class);
                startActivity(intent);
            }
        });

        banner = view.findViewById(R.id.banner);

        ArrayList<Integer> imgs = new ArrayList<>();
        imgs.add(R.drawable.c5);
        imgs.add(R.drawable.c4);
        imgs.add(R.drawable.c3);

        ArrayList<String> title = new ArrayList<>();
        title.add("2021电信诈骗受害者职业统计");
        title.add("2021电信诈骗案例特征类型统计");
        title.add("各年网络犯罪数量统计");

        ArrayList<String> web = new ArrayList<>();
        web.add("https://mp.weixin.qq.com/s/rpqT6QVnidLwM6-yXw2vPA");
        web.add("https://mp.weixin.qq.com/s/1dE1wRkDzHdIAfS48Ug8jg");
        web.add("https://mp.weixin.qq.com/s/ZWj576mYmok0aZo0Qf20sQ");


        banner.setImages(imgs);
        banner.setImageLoader((ImageLoaderInterface) new ImageLoadBanner());
        banner.setBannerTitles(title);
        banner.setDelayTime(3000);
        banner.isAutoPlay(true);
        banner.setIndicatorGravity(BannerConfig.CENTER);
        banner.setBannerAnimation(Transformer.Accordion);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                Intent intent = new Intent(getActivity(), news_details.class);
                intent.putExtra("web", web.get(position));
                startActivity(intent);
            }
        });
        banner.start();


        ViewPager2 viewPage = view.findViewById(R.id.viewPage);
        //获取适配器
        viewpagerAdapter viewPageAdapter = new viewpagerAdapter();
        //添加到ViewPager
        viewPage.setAdapter(viewPageAdapter);

        return view;

    }





    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(AntiCheatGuardViewModel.class);
        //TODO: Use the ViewModel


    }


}
class ImageLoadBanner extends ImageLoader {

    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        imageView.setImageResource(Integer.parseInt(path.toString()));
    }
}